module.exports = class extends think.Model {
    async commission(points, balance_name) {
        const user_points = await this.model('user').where({id: think.user.user_id}).getField('integral', true);
        let points_new = user_points + points;
        await this.model('user').where({id: think.user.user_id}).update({integral: points_new});

        await this.model('points').add({
            user_id: think.user.user_id,
            points_before: user_points,
            points_after: points_new,
            balance_points: points,
            balance_name: balance_name,
            node: `积分剩余：${user_points},发生积分：${points},最新积分：${points_new}`
        });
        return points_new;
    }

    async commission_qy(points, balance_name, uuid) {
        const user = await this.model('user').where({uuid: uuid}).find();
        let points_new = user.points + points;
        await this.model('user').where({uuid: uuid}).update({points: points_new});

        await this.model('points').add({
            user_id: user.id,
            points_before: user.points,
            points_after: points_new,
            balance_points: points,
            balance_name: balance_name,
            inviter_user_id: think.user.user_id,//当前用户为邀请的人
            node: `积分剩余：${user.points},发生积分：${points},最新积分：${points_new}，邀请人id:${think.user.user_id}`
        });
        return points_new;
    }

};
